#ifndef TCPSERVER_H
#define TCPSERVER_H
#include <QThread>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QHostAddress>
#include <QFile>
class TcpServer: public QThread
{
    Q_OBJECT
public:
    TcpServer();
  //  virtual void run();
 //   void stopRun();
private slots:
    void sendMessage();
    void updateServerProgress();
    void showNoConnection();
    void displayError(QAbstractSocket::SocketError);  //显示错误
    void updateSendFile(qint64); //发送数据，更新进度条

private:
    QTcpServer *tcpServer;
    QTcpSocket *tcpSocket;
    void wcclSetup(char*);
    void wcclSetup_f(char *ch);

    void dsSetup(char*);
    void dsTest();
    void xbSetup(char*);
    void xbTest();
    void lbSetup(char*);
    void muSetup(char*);
    void mnSetup(char*);
    void ft3Setup(char*);
    void lbTest();
    void reSet();
    void ysTest();
    void wzxTest();
    void smvAllChannel(char*);

    void allPageSetup();

    float m_fDelay;
    int m_iTbfs;
    int m_iLx;
    float m_fEdyc;
    int m_iEdycDw;
    int m_iJd;
    int m_iBzSelect;
    float m_fBzDyz;
    int m_iBcSelect;
    int m_iBcTd;
    int m_iBcTdLx;
    float m_fBcDyz;
    int m_iCyfs;
    QString m_sMac;
    int m_iCurrentTd;
    int m_iInput;
    int m_iCslx;
    int m_iBcsz;
    int m_iCsTime;
    int m_iTdh;
    int m_iXbcs;
    int m_iLbTime;
    int m_iMuInput;
    int m_iMuTime;

    int m_iFt3Lx;
    int m_iFt3Pl;
    int m_iFt3Btl;
    QString m_sLNName;
    QString m_sLDName;
    QString m_sDSNName;
    int m_iEddl;
    int m_iEdzxdl;
    int m_iEddy;
    QString m_sStause1;
    QString m_sStause2;
    int m_iTdNum;
    QString m_sFz[24];
    QString m_sXw[24];

    qint64 totalBytes;  //数据总大小
    qint64 bytesWritten;  //已经发送数据大小
    qint64 bytesToWrite;   //剩余数据大小
    qint64 loadSize;   //每次发送数据的大小
    QString fileName;  //保存文件路径
    QByteArray outBlock;  //数据缓冲区，即存放每次要发送的数据
    QFile *localFile;

public:
    int getTbfs(){return m_iTbfs;}
    float getMuDelay(){return m_fDelay;}
    int getLx(){return m_iLx;}
    float getEdyc(){return m_fEdyc;}
    int getEdycDw(){return m_iEdycDw;}
    int getJd(){return m_iJd;}
    int getBzSelect(){return m_iBzSelect;}
    float getBzDyz(){return m_fBzDyz;}
    int getBcSelect(){return m_iBcSelect;}
    int getCslx(){return m_iCslx;}
    int getBcTd(){return m_iBcTd;}
    int getBcTdLx(){return m_iBcTdLx;}
    float getBcDyz(){return m_fBcDyz;}
    int getCyfs(){return m_iCyfs;}
    QString getMac(){return m_sMac;}
    int getCurrentTd(){return m_iCurrentTd;}
    int getInput(){return m_iInput;}
    int getBcsz(){return m_iBcsz;}
    int getCsTime(){return m_iCsTime;}
//    float getSsTime(){return m_fSsTime;}
    int getTdh(){return m_iTdh;}
    int getXbcs(){return m_iXbcs;}
    int getLbTime(){return m_iLbTime;}
    int getMuInput(){return m_iMuInput;}
    int getMuTime(){return m_iMuTime;}
    int getXbNum(){return m_fXdyz;}
    float getXbYxz(){return m_fBfd;}

    int getFt3Lx(){return m_iFt3Lx;}
    int getFt3Pl(){return m_iFt3Pl;}
    int getFt3Btl(){return m_iFt3Btl;}
    QString getLNName(){return m_sLNName;}
    QString getLDName(){return m_sLDName;}
    QString getDSNName(){return m_sDSNName;}
    int getEddl(){return m_iEddl;}
    int getEdzxdl(){return m_iEdzxdl;}
    int getEddy(){return m_iEddy;}
    QString getStause1(){return m_sStause1;}
    QString getStause2(){return m_sStause2;}
    int getTdNum(){return m_iTdNum;}
    QString getFz(int i){return m_sFz[i];}
    QString getXw(int i){return m_sXw[i];}

    void TcpSend(QString);
    void TcpSendFile(QString);

    float m_fXdyz;
    float m_fBfd;

    int haveHarmonic;
    int h3, h5, h7, h9, h11;

signals:
    void sigTcpOrder(int);
    void sigTcpStause(int);
};

#endif // TCPSERVER_H
